package com.star.sync.elasticsearch.service.impl;

import com.star.sync.elasticsearch.dao.BaseDao;
import com.star.sync.elasticsearch.dao.CreateTable;
import com.star.sync.elasticsearch.service.TableDiffService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: canal-mysql-ddl-sync
 * @description:
 * @author: young
 * @create: 2018-08-22 09:57
 **/
@Service
public class TableDiffServiceImpl implements TableDiffService {

    @Resource
    private BaseDao baseDao;

    @Override
    public List<String> tableDiff() {
        List<String> createTables = new ArrayList<>();
        List<String> dbs = baseDao.selectDB();
        for (String db : dbs) {
            List<String> tables = baseDao.selectTableForDB(db);
            for (String t : tables) {
                Map<String, String> createTable = baseDao.showCeateTable(db, t);
                createTables.add(createTable.get("Create Table"));
            }
        }

        return createTables;
    }
}
